﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Cashier.usercontrols
{
    public class TextboxFocusExt: TextBox
    {
        public TextboxFocusExt()
            : base()
        {
        }

        /// <summary>
        /// 获得焦点事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);
            if (this.Text.Equals("0.00") || this.Text.Equals("0"))
            {
                this.Tag = this.Text;
                this.Text = String.Empty;
            }
        }

        /// <summary>
        /// 失去焦点事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);
            if (String.IsNullOrEmpty(this.Text) && this.Tag != null &&
                    (this.Tag.ToString().Equals("0") || this.Tag.ToString().Equals("0.00")))
            {
                this.Text = this.Tag.ToString();
                this.Tag = null;
            }
        }
    }
}
